﻿using System;
using System.Reflection;

namespace CardPlay.Model.Primitives
{
    public static class ExtensionsToType
    {
        public static object InvokeStatic(this Type type, string method, params object[] args)
        {
            return type.InvokeMember(method, BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, args);
        }

        public static T GetStaticField<T>(this Type type, string name)
        {
// ReSharper disable PossibleNullReferenceException
            return (T) type.GetField(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField).GetValue(null);
// ReSharper restore PossibleNullReferenceException
        }
    }
}
